import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-09
 * Time: 18:52
 */
public class two_Sum {
    public static int[] twoSum(int[] price, int target) {
        int left=0,right=price.length-1;
        Arrays.sort(price);
        int[] arr=new int[2];
        while (left<right){
            int tmp=price[left]+price[right];
            if (tmp==target){
                arr[0]=price[left];
                arr[1]=price[right];
                break;
            }else if (tmp>target){
                right--;
            }else {
                left++;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr=new int[]{3, 9, 12, 15};
        System.out.println(Arrays.toString(twoSum(arr, 18)));
    }
}
